using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Events;
using Yoozoo.UI;
using Yoozoo.UI.YGUI;

public class YButtonBinder : BinderBase
{
    public enum AttributeType : int
    {
        onClick,
        onDoubleClick,
        onLongClick,
        onLongPress,
        onDown,
        onUp,
        onInteractiveChange,
        onPointerExit,
        onPointerEnter,
        interactable,
        enabled,
        longPressTime
    }
    
    private YButton _target;
    
    public YButtonBinder(UIExpansion owner, LinkerConfig config) : base(owner, config)
    {
    }

    public YButtonBinder()
    {
        
    }

    public override void Dispose()
    {
        _target = null;
        base.Dispose();
    }

    public override void Init(LinkerConfig config)
    {
        GameObject targetGo = _owner.GetStoredGameObject(config.StoredGameObjectIndex);
        if (targetGo == null)
        {
            return;
        }
        _target = targetGo.GetComponent<YButton>();
        _active = _target != null;
    }
    public override void SetAction2(UnityAction action)
    {
        switch ((AttributeType)Enum.Parse(typeof(AttributeType), _linkerType))
        {
            case AttributeType.onClick:
                _target.onClick.AddListener(action);
            break;
            case AttributeType.onDoubleClick:
                _target.onDoubleClick.AddListener(action);
            break;
            case AttributeType.onLongClick:
                _target.onLongClick.AddListener(action);
            break;
            case AttributeType.onLongPress:
                _target.onLongPress.AddListener(action);
            break;
            case AttributeType.onDown:
                _target.onDown.AddListener(action);
            break;
            case AttributeType.onUp:
                _target.onUp.AddListener(action);
            break;
            case AttributeType.onInteractiveChange:
                _target.onInteractiveChange.AddListener(action);
            break;
            case AttributeType.onPointerExit:
                _target.onPointerExit.AddListener(action);
            break;
            case AttributeType.onPointerEnter:
                _target.onPointerEnter.AddListener(action);
            break;
            default:
            break;
        }
        base.SetAction2(action);
    }
    
    public override void RemoveAction2(UnityAction action)
    {
        switch ((AttributeType)Enum.Parse(typeof(AttributeType), _linkerType))
        {
            case AttributeType.onClick:
                _target.onClick.RemoveListener(action);
            break;
            case AttributeType.onDoubleClick:
                _target.onDoubleClick.RemoveListener(action);
            break;
            case AttributeType.onLongClick:
                _target.onLongClick.RemoveListener(action);
            break;
            case AttributeType.onLongPress:
                _target.onLongPress.RemoveListener(action);
            break;
            case AttributeType.onDown:
                _target.onDown.RemoveListener(action);
            break;
            case AttributeType.onUp:
                _target.onUp.RemoveListener(action);
            break;
            case AttributeType.onInteractiveChange:
                _target.onInteractiveChange.RemoveListener(action);
            break;
            case AttributeType.onPointerExit:
                _target.onPointerExit.RemoveListener(action);
            break;
            case AttributeType.onPointerEnter:
                _target.onPointerEnter.RemoveListener(action);
            break;
            default:
            break;
        }
        base.RemoveAction2(action);
    }

    public override void SetSingle(float value)
    {
        switch ((AttributeType)Enum.Parse(typeof(AttributeType), _linkerType))
        {
            case AttributeType.longPressTime:
                _target.LongPressTime = value;
                break;
            default:
                break;
        }
        base.SetSingle(value);
    }
    public override void SetBoolean(bool value)
    {
        switch ((AttributeType)Enum.Parse(typeof(AttributeType), _linkerType))
        {
            case AttributeType.interactable:
                _target.interactable = value;
            break;
            case AttributeType.enabled:
                _target.enabled = value;
            break;
            default:
            break;
        }
        base.SetBoolean(value);
    }
    
    public override void RemoveAllAction()
    {
        switch ((AttributeType)Enum.Parse(typeof(AttributeType), _linkerType))
        {
            case AttributeType.onClick:
                _target.onClick.RemoveAllListeners();
            break;
            case AttributeType.onDoubleClick:
                _target.onDoubleClick.RemoveAllListeners();
            break;
            case AttributeType.onLongClick:
                _target.onLongClick.RemoveAllListeners();
            break;
            case AttributeType.onLongPress:
                _target.onLongPress.RemoveAllListeners();
            break;
            case AttributeType.onDown:
                _target.onDown.RemoveAllListeners();
            break;
            case AttributeType.onUp:
                _target.onUp.RemoveAllListeners();
            break;
            case AttributeType.onInteractiveChange:
                _target.onInteractiveChange.RemoveAllListeners();
            break;
            case AttributeType.onPointerExit:
                _target.onPointerExit.RemoveAllListeners();
            break;
            case AttributeType.onPointerEnter:
                _target.onPointerEnter.RemoveAllListeners();
            break;
            default:
            break;
        }
    }
    
}